package com.zzl.boot.bigevent.service.impl;

import com.zzl.boot.bigevent.mapper.categoryMapper;
import com.zzl.boot.bigevent.pojo.category;
import com.zzl.boot.bigevent.pojo.result;
import com.zzl.boot.bigevent.service.categoryService;
import com.zzl.boot.bigevent.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class implCategoryService implements categoryService {
    @Autowired
    private categoryMapper categoryMapper;
    private Map<String,Object> map;
    @Override
    public void addCategory(category category) {
        categoryMapper.addCategory(category);
    }

    @Override
    public List<category> getAllCategory() {
        return categoryMapper.getAllCategory();
    }

    @Override
    public category getCategoryDetail(Integer id) {
        return categoryMapper.getCategoryDetail(id);
    }

    @Override
    public void updateCategory(category category) {
        categoryMapper.updateCategory(category);
    }

    @Override
    public result delById(Integer id) {
        map = ThreadLocalUtil.get();
        if(categoryMapper.artilceCount(id) > 0){
            return result.error("该分类有文章关联，不能删除");
        }
        categoryMapper.delById(id);
        return result.success();
    }
}
